const classModel = require('../model/classModel');

module.exports.find = async function(searchObj,page){
    let {current,pageSize} = page;
    // 根据查询条件获取总数
    let total = await classModel.countDocuments(searchObj);
    // 根据查询条件获取具体数量的数据
    let data = await classModel.find(searchObj)
                    .limit(pageSize)
                    .skip((current - 1) * pageSize);
    return {
        current,pageSize,total,rows:data,
    }
}

// 不带分页查询
module.exports.findAll = async function(){
    return await classModel.find();
}

module.exports.findById = async function(id){
    return await classModel.findById(id);
}